package com.roc.web.action.settlement;

import java.util.ArrayList;
import java.util.List;

import com.roc.page.BaseSearchCondition;
import com.roc.page.WhereHQLFieldBean;
import com.roc.util.Constance;
import com.roc.util.constant.Role;

public class SettleInfoSearchCondition extends BaseSearchCondition{
	private String minDate;//交易日期范围1
	private String maxDate;//交易日期范围2
	private String bankAccount;//结算银行账号
	private String bankAccountName;//结算银行账号名
	private String businessNum;//商户号
	private String businessName;//商户名
	private String billStatus;//结算状态
	private String freezeState;//冻结状态
	private String orgCode;//机构代码
//	private String obj;//子代理商
	private String opId;
	private String agentId;//当前商户的代理商id
	private String roleType;
	private String marketorId;
	private String ucbccdArea;
	
	@Override
	protected List<WhereHQLFieldBean> getWhereHQLFieldBeanList() {
		List<WhereHQLFieldBean> filedBeanList = new ArrayList<WhereHQLFieldBean>();
		if(Constance.isNotEmpty(minDate)){
//			filedBeanList.add(new WhereHQLFieldBean("tp.SETTLEDATE",minDate.trim(),">=",false));
			filedBeanList.add(new WhereHQLFieldBean("tp.dt_create >= to_date('"+minDate.trim()+"', 'yyyymmdd')"));
		}
		if(Constance.isNotEmpty(maxDate)){
//			filedBeanList.add(new WhereHQLFieldBean("tp.SETTLEDATE",maxDate.trim(),"<=",false));
			filedBeanList.add(new WhereHQLFieldBean("tp.dt_create < to_date('"+maxDate.trim()+"', 'yyyymmdd' )+ 1 "));
		}
		//结算银行账号
		if(Constance.isNotEmpty(bankAccount)){
			filedBeanList.add(new WhereHQLFieldBean("tp.ACCOUNT",bankAccount.trim(),"=",false));
		}
		//结算银行账号名
		if(Constance.isNotEmpty(bankAccountName)){
			filedBeanList.add(new WhereHQLFieldBean("tp.ACCOUNT_NAME",bankAccountName.trim(),"LIKE",false,"ALL"));
		}
		//商户号
		if(Constance.isNotEmpty(businessNum)){
			filedBeanList.add(new WhereHQLFieldBean("tp.MCHT_CD",businessNum.trim(),"=",false));
		}
		//商户名
		if(Constance.isNotEmpty(businessName)){
			filedBeanList.add(new WhereHQLFieldBean("tp.MCHT_NAME",businessName.trim(),"LIKE",false,"ALL"));
		}
		//机构编号
		if (Constance.isNotEmpty(orgCode)) {
			filedBeanList.add(new WhereHQLFieldBean("tp.INS_ID_CD", orgCode.trim(), "=", false));
		}
		
		if(Constance.isNotEmpty(opId)){//操作员 
	    	filedBeanList.add(new WhereHQLFieldBean("tm.rec_upd_opr", opId.trim(), "=", false));
	    }
		
		if(Constance.isNotEmpty(ucbccdArea)){//运维人员
			filedBeanList.add(new WhereHQLFieldBean("tm.uc_bc_cd_area", ucbccdArea.trim(), "=", false));
		}
		return filedBeanList;
	}
	@Override
	protected String getRowCountHQL() {
		StringBuffer sb = new StringBuffer();
		sb.append("select count(*) from T_TRANSJNLS_SETTLE tp,TBL_MCHT_INF tm ");
		if (roleType.equals(Role.AGENT.getCode() )||roleType.equals(Role.SFB_AGENT.getCode() )) {
			sb.append(",tbl_mer_agent_relation ma ");
		}
		
		sb.append("where tp.MCHT_CD = tm.mcht_cd ");
		if (roleType.equals(Role.AGENT.getCode() )||roleType.equals(Role.SFB_AGENT.getCode() )) {
			sb.append("and tp.MCHT_CD = ma.merno and ma.agentid= '"+agentId+"' ");
		}
		if(roleType.equals(Role.MARKET_DIRECT.getCode()) || roleType.equals(Role.MARKET_LEAD.getCode())){
			sb.append(" and exists (select 1 from t_oper_role tor where tm.uc_bc_cd_area = tor.agentid and tor.operid ="+marketorId+") ");
		}
		return sb.toString();
	}
	@Override
	protected String getSearchHQL() {
		StringBuffer sb = new StringBuffer();
		sb = sb.append(
				"select tp.MCHT_CD,tp.MCHT_NAME,tp.MCHT_SET_AMT,tp.MCHT_FEE, ")
				.append("tp.ACCOUNT_NAME,tp.BANK_NAME,tp.ACCOUNT,tp.SETTLEDATE ");
		sb.append("from T_TRANSJNLS_SETTLE tp,TBL_MCHT_INF tm ");
		if (roleType.equals(Role.AGENT.getCode() )||roleType.equals(Role.SFB_AGENT.getCode() )) {
			sb.append(",tbl_mer_agent_relation ma ");
		}
		
		sb.append("where tp.MCHT_CD = tm.mcht_cd ");
		if (roleType.equals(Role.AGENT.getCode() )||roleType.equals(Role.SFB_AGENT.getCode() )) {
			sb.append("and tp.MCHT_CD = ma.merno and ma.agentid= '"+agentId+"' ");
		}
		if(roleType.equals(Role.MARKET_DIRECT.getCode()) || roleType.equals(Role.MARKET_LEAD.getCode())){
			sb.append(" and exists (select 1 from t_oper_role tor where tm.uc_bc_cd_area = tor.agentid and tor.operid ="+marketorId+") ");
		}
		return sb.toString();
	}
	@Override
	protected String getOrderPartOfHQL() {
		return "order by tp.SETTLEDATE desc";
	}
	
	
	public String getMinDate() {
		return minDate;
	}
	public void setMinDate(String minDate) {
		this.minDate = minDate;
	}
	public String getMaxDate() {
		return maxDate;
	}
	public void setMaxDate(String maxDate) {
		this.maxDate = maxDate;
	}
	public String getBankAccount() {
		return bankAccount;
	}
	public void setBankAccount(String bankAccount) {
		this.bankAccount = bankAccount;
	}
	public String getBankAccountName() {
		return bankAccountName;
	}
	public void setBankAccountName(String bankAccountName) {
		this.bankAccountName = bankAccountName;
	}
	public String getBusinessNum() {
		return businessNum;
	}
	public void setBusinessNum(String businessNum) {
		this.businessNum = businessNum;
	}
	public String getBusinessName() {
		return businessName;
	}
	public void setBusinessName(String businessName) {
		this.businessName = businessName;
	}
	public String getBillStatus() {
		return billStatus;
	}
	public void setBillStatus(String billStatus) {
		this.billStatus = billStatus;
	}
	public String getFreezeState() {
		return freezeState;
	}
	public void setFreezeState(String freezeState) {
		this.freezeState = freezeState;
	}
	public String getOrgCode() {
		return orgCode;
	}
	public void setOrgCode(String orgCode) {
		this.orgCode = orgCode;
	}
	/*public String getObj() {
		return obj;
	}
	public void setObj(String obj) {
		this.obj = obj;
	}*/
	public String getOpId() {
		return opId;
	}
	public void setOpId(String opId) {
		this.opId = opId;
	}
	public String getAgentId() {
		return agentId;
	}
	public void setAgentId(String agentId) {
		this.agentId = agentId;
	}
	public String getRoleType() {
		return roleType;
	}
	public void setRoleType(String roleType) {
		this.roleType = roleType;
	}
	public String getMarketorId() {
		return marketorId;
	}
	public void setMarketorId(String marketorId) {
		this.marketorId = marketorId;
	}
	public String getUcbccdArea() {
		return ucbccdArea;
	}
	public void setUcbccdArea(String ucbccdArea) {
		this.ucbccdArea = ucbccdArea;
	}
	
}
